/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import controller.AddLab;
import entities.Lab;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author QUY-THI
 */
@ManagedBean
@ViewScoped
public class AddLabBean {

    private String labname;
    private String description;

    public String getLabname() {
        return labname;
    }

    public void setLabname(String labname) {
        this.labname = labname;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Creates a new instance of AddLabBean
     */
    public AddLabBean() {
    }

    public String resultAdd() {
        AddLab al = new AddLab();
        Lab l = new Lab();
        l.setCreateDate(new Date());
        l.setLabname(labname);
        l.setDescription(description);
        l.setStatus(Boolean.TRUE);
        boolean addLab = al.addLab(l);
        if (addLab) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Success"));
            return "";
        }
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Error please try again later"));
        return "";
    }
}
